package com.biu.billiards.utils;



import com.fasterxml.jackson.databind.ObjectMapper;
import com.icbc.api.DefaultIcbcClient;
import com.icbc.api.IcbcConstants;
import com.icbc.api.request.MybankEnterpriseAccountQaccbalRequestV1;
import com.icbc.api.response.MybankEnterpriseAccountQaccbalResponseV1;

import java.time.LocalDate;
import java.time.LocalDateTime;
import java.time.YearMonth;
import java.time.format.DateTimeFormatter;
import java.util.ArrayList;
import java.util.UUID;

import static cn.hutool.json.XMLTokener.entity;

/**
 * @author biuwu
 */

public class test {


    protected static String APP_ID = "11000000000000017183";
    protected static String APIGW_PUBLIC_KEY ="MIGfMA0GCSqGSIb3DQEBAQUAA4GNADCBiQKBgQCMpjaWjngB4E3ATh+G1DVAmQnIpiPEFAEDqRfNGAVvvH35yDetqewKi0l7OEceTMN1C6NPym3zStvSoQayjYV+eIcZERkx31KhtFu9clZKgRTyPjdKMIth/wBtPKjL/5+PYalLdomM4ONthrPgnkN4x4R0+D4+EBpXo8gNiAFsNwIDAQAB";
    protected static String PRI_KEY = "MIIEvQIBADANBgkqhkiG9w0BAQEFAASCBKcwggSjAgEAAoIBAQCMkDuWS2UiVIJMmer65m6iLbidIGysjxwiOwLPLNuapRETVgXnO+a4hxJnh/ZoODz6zcrm5AmNLrzPr0slku1RvT/8w/4T2bViQq3/irG1ntrVKNyLakiGRbWN1Ldz2121XaE037FjrmDQwiNH1DTm/DwezgjNYaXYzASEZsXt0p+MoBnOhLaYfMr/fXwRMooKAg5pJ2pDml0cupuapvwUwGAKQxYP4fdU8kzKn+7OSvJT1K8UjdhDaEJ0uecSJqoCccrf6MTzoXIfa/2jCiDXsKorzIOSRszRAFP4CZlX0Z0a2g4MUqrRl3fxOaqZC+w0/Z7PeescjNrZCgJ9P62nAgMBAAECggEARtGoY+mqk6hWWbe2ryCIHwfAGtIqTqpvt0NZ//2OyxRdTQurP7xrWw8ak7Tpzcp/1rD2iGvd8BbbJBwiVVT4YpVh9rzcdy3Z+B62QaikLmhRwtGqhEdRMO1QMpw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otXJgwNk58UvQkwW8qTx5Z73Mi+0mFd/A=";



    protected static String BASE_URL = "https://gw.open.icbc.com.cn/api";


    public static void main(String[] args) {
        // 获取当前日期
        LocalDate currentDate = LocalDate.now();
        // 定义日期格式
        DateTimeFormatter formatter = DateTimeFormatter.ofPattern("yyyyMMdd");
        // 将日期格式化为字符串
        String formattedDate = currentDate.format(formatter);


        // 获取当前日期和时间
        LocalDateTime currentDateTime = LocalDateTime.now();

        // 定义日期时间格式
        DateTimeFormatter formatter2 = DateTimeFormatter.ofPattern("yyyyMMddHHmmssSSS");

        // 将日期时间格式化为字符串
        String formattedDateTime = currentDateTime.format(formatter2);


        System.out.println("formattedTime212312");

        System.out.println(formattedDateTime);
        String URI = "mybank/enterprise/account/qaccbal/V1";

         //DefaultIcbcClient client = new DefaultIcbcClient(APP_ID, PRI_KEY, APIGW_PUBLIC_KEY);

    //    DefaultIcbcClient client = new DefaultIcbcClient(APP_ID, CA_PRIVATE_STR, APIGW_PUBLIC_KEY, CA_PUBLIC_STR, CA_PASSWORD);


        DefaultIcbcClient client = new DefaultIcbcClient(APP_ID, IcbcConstants.SIGN_TYPE_RSA2, PRI_KEY, IcbcConstants.CHARSET_UTF8, IcbcConstants.FORMAT_JSON,APIGW_PUBLIC_KEY, IcbcConstants.ENCRYPT_TYPE_AES,"", "", "");


        ArrayList<MybankEnterpriseAccountQaccbalRequestV1.MybankEnterpriseAccountQaccbalRequestRdV1> rd = new ArrayList<>();
        MybankEnterpriseAccountQaccbalRequestV1.MybankEnterpriseAccountQaccbalRequestRdV1 rdV1 =  new MybankEnterpriseAccountQaccbalRequestV1.MybankEnterpriseAccountQaccbalRequestRdV1();
        rdV1.setAccountNo("1103021009200566609");

        rdV1.setiSeqno("1");

        rd.add(rdV1);
        try {

            MybankEnterpriseAccountQaccbalRequestV1.MybankEnterpriseAccountQaccbalRequestBizV1 bizContent =
                    new MybankEnterpriseAccountQaccbalRequestV1.MybankEnterpriseAccountQaccbalRequestBizV1();

            MybankEnterpriseAccountQaccbalRequestV1 request =
                    new MybankEnterpriseAccountQaccbalRequestV1();
            // 请对照接口文档用bizContent.setxxx()方法对业务上送数据进行赋值

            bizContent.setTransCode("QACCBAL");
            bizContent.setCis("110390003267826");
            bizContent.setBankCode("102");
            bizContent.setLoginId("6609.y.1103.y.1103");
            bizContent.setTranDate(formattedDate);
            bizContent.setfSeqno(UUID.randomUUID().toString());
            bizContent.setTranTime(formattedDateTime);
            bizContent.setTotalNum(1);
            bizContent.setRd(rd);

            bizContent.setfSeqno("123");

            request.setServiceUrl(BASE_URL + "/" + URI);
            request.setBizContent(bizContent);
            // 输出余额查询响应对象，需根据实际调用服务更换（MybankEnterpriseAccountQaccbalResponseV1）
            MybankEnterpriseAccountQaccbalResponseV1 response = client.execute(request);

            if (response.isSuccess()) {
                // 业务成功处理
                System.out.println("success");//


                ObjectMapper objectMapper = new ObjectMapper();
                String json = objectMapper.writeValueAsString(response);
                System.out.println(json);

            } else {
                System.out.println("error");
                ObjectMapper objectMapper = new ObjectMapper();
                String json = objectMapper.writeValueAsString(response);
                System.out.println(json);
                // 失败

            }

        } catch (Exception e) {
            e.printStackTrace();
        }

    }





//        GetMtVo getMtVo =new GetMtVo();
//        getMtVo.setMtKey("07aa028d54665491");
//        getMtVo.setMtSecret("e1b70b8e87680844b91d287e87a95ec4f024ea05");
//
//        getMtVo.setAuthCode("bf57497dd0fb8681b1d2f0549d1b008160c492fd");
//
//        System.out.println("getMtVoasdasf");
//        System.out.println(getMtVo);
//        MtUtils.getAuth(getMtVo);

//        YearMonth yearMonth= YearMonth.now();
//        int daysInMonth = yearMonth.lengthOfMonth();
//        System.out.println(daysInMonth);

       // System.out.println("当前时间小时："+ LocalDateTime.now().getHour());
//        int nowHour = LocalDateTime.now().getHour();
//
//        System.out.println("当前时间是"+nowHour);
//        int now=14;
//
//         int start = 7;
//         int end = 14;
//
//         if (now>=start && now+1<=end){
//             System.out.println("可以开台");
//         }else {
//             System.out.println("不可以关台");
//         }




}
